import './index.scss'
import  * as zpkgs from './zpkgs/index'
import * as formHooks from './zpkgs/hooks/form'

// import {useDataTable} from "./zpkgs/hooks/datatable";
export let hooks = {
  // useDataTable
}

export { defZFormFieldCom, getFieldMixinDefMap } from './zform/render'


import _CurdHelper from "./zpkgs/ext/CurdHelper";
export let CurdHelper = _CurdHelper

/**
 *
 * @type {{FormTextarea?: function(...[*]): {ui: (*&{widget: string, label: string, widgetConfig: {}}), type: string}, FormSelect?: function(*=, *=): {ui: (*&{label: string, widgetConfig: {}}), type: string}, FormBase?: function(*=, {ui: *, widgetConfig?: *}=): {ui: *&{label: string, widgetConfig: {}}, type: string}, FormCheckbox?: function(*=, *=): {ui: (*&{label: string, widgetConfig: {}}), type: string}, FormRadio?: function(*=, *=): {ui: (*&{label: string, widgetConfig: {}}), type: string}, FormInputNativeNumber?: function(*=, {ui: *, widgetConfig?: *}=): {ui: *&{widget: string, label: string, widgetConfig: {type: string}}, type: string}, FormInputNativeInteger?: function(...[*]): {ui: (*&{widget: string, label: string, widgetConfig: {type: string}}), type: string}, FormColorPicker?: function(*=, *=): {ui: (*&{label: string, widgetConfig: {}}), type: string}, FormSimpleUploader?: function(*=, *=): {ui: (*&{label: string, widgetConfig: {}}), type: string}, FormDatePicker?: function(*=, *=): {ui: *&{label: string, widgetConfig: {}}, type: string}, FormInputNumber?: function(*=, *=): {ui: (*&{label: string, widgetConfig: {}}), type: string}, FormImgUploader?: function(*=, *=): {ui: (*&{label: string, widgetConfig: {}}), type: string}, FormInput?: function(*=, {ui: *, widgetConfig?: *}=): {ui: *&{widget: string, label: string, widgetConfig: {}}, type: string}}}
 */
export let FormHelper = formHooks

import  { initZForm, buildVueComponentMan } from './zform/init';

import { Fragment } from 'vue-frag'

/**
 *
 * @param Vue
 * @param ready
 * @param ELEMENT
 * @param VueCompositionPlugin
 * @param Lib
 */
export function initZPkgs(Vue, ready, {ELEMENT, VueCompositionPlugin, Lib} = {}) {
  // console.log(VueCompositionApi)
  // installDirectives(Vue)
  Vue.component('ZFragment', Fragment)
  globalThis.ZELEMENT = ELEMENT
  // Vue.use(Fragment.Plugin)
  if (Vue.version.startsWith('2.6')) {
    Vue.use(VueCompositionPlugin);
  }

  globalThis.vueCompositionAPI = Lib

  zpkgs.install(Vue, ELEMENT)
  // Vue.use(zpkgs);
  globalThis.ZCONSOLE = {
    log(...args) {
      if (window.Z_DEBUG) {
        console.log(...args)
      }
    },
    warn(...args) {
      console.log(...args)
    }
  }
  globalThis.CustomCusComponent = class extends buildVueComponentMan(Vue) {}
  globalThis.ZCACHE_VUE = Vue
  if (ready) {
    ready({initZForm, buildVueComponentMan})
  }
}

export let COMPONENTS = zpkgs.default

export function installComponents(Vue) {
  Object.entries(COMPONENTS).forEach(([key, item]) => {
    Vue.component(key, item)
  })
}

export let Mixins =  {
...zpkgs.Mixins
}

export default {
  Mixins: {
    ...zpkgs.Mixins
  },
}
